Step 1 - Use the Kanzi Engine API to load a Kanzi binary

When you create a new Kanzi Studio project with C++ application, Kanzi Studio creates a project with a Microsoft Visual Studio solution that includes the Kanzi application template source code.

Kanzi creates a Kanzi Studio project in <KanziWorkspace>/Projects/<ProjectName>/Tool_project directory and the structure for the Visual Studio solution for your project in <KanziWorkspace>/Projects/<ProjectName>/Application:

Assets for the tutorial

The starting point of this tutorial is stored in the <KanziWorkspace>/Tutorials/Programmer tutorial/Start directory:

The <KanziWorkspace>/Tutorials/Programmer tutorial/Completed directory contains the completed project of this tutorial.

Use the Kanzi Engine API to load a Kanzi binary

To use the Kanzi Engine API to load a Kanzi binary:

  1. In Kanzi Studio open the <KanziWorkspace>/Tutorials/Programmer tutorial/Start/Tool_project/Programmer tutorial.kzproj Kanzi Studio project and select File > Export > Export KZB.
    Kanzi Studio creates the kzb file and configuration files from your Kanzi Studio project. Kanzi Studio stores the exported files in the <ProjectName>/Application/bin directory or the location you specify in the Binary Export Directory property in Project > Properties. The kzb file contains all nodes and resources from your Kanzi Studio project, except the resources you mark in a localization table as locale packs.
    When you run your Kanzi application from Visual Studio, your application loads the kzb file and configuration files.
  2. In Visual Studio open the solution stored in <KanziWorkspace>/Tutorials/Programmer tutorial/Start/Application/configs/platforms/win32/Programmer_tutorial.sln.
    If you open the tutorial solution in Visual Studio 2017, when asked to retarget the project to the latest Microsoft toolset, click Cancel.
  3. In Visual Studio set the Programmer tutorial as your startup project, and open the programmer_tutorial.cpp file.
    The programmer_tutorial.cpp file contains the minimum amount of code required for loading a Kanzi application. In this tutorial you create the logic of your application in this file.
    // The kanzi.hpp header includes all Kanzi Engine functionality.
    // To fine-tune your application you can include only the relevant headers.
    // See API reference.
    #include <kanzi/kanzi.hpp>
    
    using namespace kanzi;
    class ProgrammerTutorialApplication: public ExampleApplication
    {
        // In the onConfigure function you can tell your Kanzi application which kzb file
        // to load, enable performance information in your application, and set how many threads
        // you want to use for loading the application resources.
        // See Application configuration reference.
        virtual void onConfigure(ApplicationProperties& configuration) KZ_OVERRIDE
        {
            configuration.binaryName = "Programmer_tutorial.kzb.cfg";
        }
    };
    
    // To work with the main function in the Application framework you need to
    // return your application in the createApplication function. The main
    // function then passes the control to the main loop defined in your
    // Application class.
    Application* createApplication()
    {
        return new ProgrammerTutorialApplication;
    }
  4. In Visual Studio select one of the solution configurations for your version of Visual Studio and run your application.
    For example, if you are still developing your application, select the GL_vs2015_Debug configuration. If you want to create a production version of your Kanzi application, select one of the available release configurations.

    When you build and run the program, Kanzi loads the kzb file and shows the application content.

    During an application launch Kanzi:
    1. Calls the onConfigure entry point function, where you specify the configuration. For example, which Kanzi Studio project kzb files you want the application to load and the application window size.
    2. Loads the kzb file to memory, which makes it available to the application.
    3. When Kanzi completes the loading of the project, it calls the onProjectLoaded function. In the next steps of this tutorial you add the application functionality in this function.

< INTRODUCTION
NEXT STEP >

See also

Application configuration reference

Using kzb files

Deploying Kanzi applications

API reference